

import java.io.*;

public class DiffComp {
	
	public static int lineCount;
	public boolean ok;
	
	private File dirTest = new File(".");
	private File dirOrig = new File(".");
	
	DiffComp(){
		lineCount = 0;
		ok = true;
	}
	
	public void compute(String testNr)  {
		String fileToCompare = "teszt";
		String originalFile = "gold";
		
		try {
			dirTest = new File (dirTest.getCanonicalFile() + File.separator + "teszteredmeny");
			dirOrig = new File (dirOrig.getCanonicalPath() + File.separator + "golden");
		
			fileToCompare = dirTest.getCanonicalPath() + File.separator + fileToCompare + testNr + ".txt";
			originalFile = dirOrig.getCanonicalPath() + File.separator + originalFile + testNr + ".txt";
		} catch (IOException e1) {
	
		}
		FileReader frTest;
		FileReader frOrig;
		try {
			
			frTest = new FileReader(fileToCompare);
			BufferedReader brTest = new BufferedReader(frTest);
			
			frOrig = new FileReader(originalFile);
			BufferedReader brOrig = new BufferedReader(frOrig);
			
			
			while (true) 
			{
				lineCount++;
				String testLine = brTest.readLine();
				String origLine = brOrig.readLine();
						
				if (testLine == null && origLine == null && ok) Result(testLine,origLine,ok);
				if (testLine == null || origLine == null) return;
				
				
				if (!testLine.equals(origLine)) 
				{
		
					if (!ok) { System.out.println("Az ellenorzes veget ert."); break;}
					ok = false;
					System.out.println("A ket file nem egyezik meg. Az elso hiba helye:");
					Result(testLine,origLine,ok);
						
				}
				
			}
				
			brTest.close();
			brOrig.close();
			
		} catch (IOException e) {
			if ((!e.getMessage().equals(""))) System.out.println("Nem sikerult megnyitni a file-okat.\n");
			//System.out.println("\nAz ellenorzes veget ert.");
	}
}	
	
	public void Result(String s, String ss, boolean ok) {
		
	
				if (ok){
					System.out.println("A teszteset altal generalt fajl megegyezik az elvart fajl tartalmaval.\n");
				}
				else {
					System.out.println(lineCount + ". sor");
					System.out.println("Elvart sor: \n" + ss );
					System.out.println("Beolvasott sor: \n" + s + "\n");
				}
						
	}
	
	
	
	
	
	
}
